<?php
require_once(dirname(dirname(__FILE__)) . '/app.php');
header('Content-Type: application/xml; charset=UTF-8');

$daytime = strtotime(date('Y-m-d'));
$condition = array( 
		'team_type' => 'normal',
		"begin_time <= {$daytime}",
		"end_time > {$daytime}",
		'audit_status' => 0,
		'is_show_api' => 'Y',
		);

/* city filter 
$ename = strval($_GET['ename']);
if ($ename && $ename!='none') {
	$city = DB::LimitQuery('category', array(
		'condition' => array(
			'zone' => 'city',
			'ename' => $ename,
		),
		'one' => true,
	));
}
if ($ename||$city) $condition['city_id'] = array(0,abs(intval($city['id'])));
 end city filter */

$teams = DB::LimitQuery('team', array(
			'condition' => $condition,
			'order' => 'ORDER BY id DESC',
			));

$oa = array();
$si = array(
		'sitename' => $INI['system']['sitename'],
		'wwwprefix' => $INI['system']['wwwprefix'],
		'imgprefix' => $INI['system']['imgprefix'],
		);

foreach($teams AS $one) {
	$city = Table::Fetch('category', $one['city_id']);
	$group = Table::Fetch('category', $one['group_id']);
	$city_qu = Table::Fetch('city_qu', $one['qu_id']);
	$item = array();
	$item['loc'] = $si['wwwprefix'] . "/team.php?id={$one['id']}"."&ad=hao123";
	$item['data'] = array();
	$item['data']['display'] = array();

	$o = array();
	$o['website'] = $INI['system']['sitename'];
	$o['siteurl'] = $INI['system']['wwwprefix'];
	($o['city'] = $city['name']) || ($o['city'] = '全国');
	//（分别对应——1代表"餐饮美食"，2代表"休闲娱乐"，3代表"生活服务"，4代表"网上购物"，5代表"酒店旅游"）
	$class=$group['name'];
	$cate_api_arr = unserialize($one['cate_api']);
	$cate_baidu_arr = explode('>', $cate_api_arr['baidu']);
	$cate_baidu_var = $cate_baidu_arr[0];//已选择的百度API一级分类值
	switch ($cate_baidu_var) {
		case '餐饮美食':
			$cate_baidu_var = '1';
		break;
		case '休闲娱乐':
			$cate_baidu_var = '2';
		break;
		case '生活服务':
			$cate_baidu_var = '3';
		break;
		case '网上购物':
			$cate_baidu_var = '4';
		break;
		case '酒店旅游':
			$cate_baidu_var = '5';
		break;
		case '丽人':
			$cate_baidu_var = '6';
		break;
		default:
			$cate_baidu_var = '3';
	}
	$o['category'] = $cate_baidu_var;
	if($cate_baidu_arr[1]){
		$o['subcategory'] = $cate_baidu_arr[1];
	}else{
		$o['subcategory'] = $one['seo_keyword'];
	}
	
    /* 三级分类 */
    $o['characteristic'] = null;
    $o['destination'] = null;
    $o['thrcategory'] = null;
    if($o['category'] == 1){ //餐饮美食 三级分类为“餐饮特色”
        $o['characteristic'] = $cate_baidu_arr[2];
        $o['destination'] = null;
        $o['thrcategory'] = null;
    }
    if($o['category'] == 4){ //网上购物 三级分类为“网购商品三级分类”
        $o['characteristic'] = null;
        $o['destination'] = null;
        $o['thrcategory'] = $cate_baidu_arr[2];
    }
    if($o['category'] == 5){ //酒店旅游 三级分类为“旅游目的地”
        $o['characteristic'] = null;
        $o['destination'] = $cate_baidu_arr[2];
        $o['thrcategory'] = null;
    }
    /* 判断三级分类 end */
	$o['dpshopid'] = null;
	$p = Table::Fetch('partner', $one['partner_id']);
	$o['range'] = $city_qu['name'];
	$o['address'] = $p['address'];
	$dex++;
	if($dex==1){$o['major'] = $dex;}else{$o['major'] = 0;}
	$o['title'] = $one['title'];
	$o['image'] = team_image($one['image']);
	$o['startTime'] = $one['begin_time'];
	$o['endTime'] = $one['end_time'];
    if ($one['state']=='soldout') $o['endTime'] = time()-3600*8;
	$o['value'] = $one['market_price'];
	$o['price'] = $one['team_price'];
	if ( $one['market_price'] > 0 ) {
		$o['rebate'] = moneyit(10*$one['team_price']/$one['market_price']);
	} else {
		$o['rebate'] = '0';
	}
	$o['bought'] = abs(intval($one['now_number']));
	$o['name'] = $one['product'];
	$o['seller'] = $p['title'];
	$o['phone'] = $p['phone'];

	$item['data']['display'] = $o;
	$oa[] = $item;
}

Output::XmlBaidu($oa);
